<template>
  <div style="width:1200px">
    <div class="xian"></div>
    <el-card class="box-card">
      公司信息
      <el-form ref="form" :model="form" label-width="100px" size="small">
        <el-form-item label="网站标题">
          <el-input v-model="form.title" maxlength="500" placeholder="请输入描述网站的标题"></el-input>
        </el-form-item>
        <el-form-item label="网站关键字">
          <el-input v-model="form.keywords" maxlength="500" placeholder="请输入描述网站的关键字"></el-input>
        </el-form-item>
        <el-form-item label="网站描述">
          <el-input v-model="form.description" maxlength="500" placeholder="请输入描述网站的详细信息"></el-input>
        </el-form-item>
        <el-form-item label="网站Logo上">
          <el-row :gutter="1">
            <el-col :span="10">
              <el-input v-model="form.logoUrl" maxlength="500" placeholder="请上传网站Logo"></el-input>
            </el-col>
            <el-col :span="4">
              <el-upload action="/api/uploadImg" name="multipartFile" :show-file-list="false" accept="image/*" :on-success="logoSuccess" :on-error="uploadError">
                <el-button type="primary">上传
                  <i class="el-icon-upload el-icon--right"></i>
                </el-button>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="网站Logo下">
          <el-row :gutter="1">
            <el-col :span="10">
              <el-input v-model="form.other1" maxlength="500" placeholder="请上传网站Logo"></el-input>
            </el-col>
            <el-col :span="4">
              <el-upload action="/api/uploadImg" name="multipartFile" :show-file-list="false" accept="image/*" :on-success="logoSuccess1" :on-error="uploadError">
                <el-button type="primary">上传
                  <i class="el-icon-upload el-icon--right"></i>
                </el-button>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        
        <el-form-item label="微信二维码">
          <el-row :gutter="1">
            <el-col :span="10">
              <el-input v-model="form.other2" maxlength="500" placeholder="微信二维码"></el-input>
            </el-col>
            <el-col :span="4">
              <el-upload action="/api/uploadImg" name="multipartFile" :show-file-list="false" accept="image/*" :on-success="logoSuccess2" :on-error="uploadError">
                <el-button type="primary">上传
                  <i class="el-icon-upload el-icon--right"></i>
                </el-button>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="右上角电话">
          <el-input v-model="form.cellPhone" maxlength="500" placeholder="请输入联系电话"></el-input>
        </el-form-item>
         
        <el-form-item label="底部电话">
          <el-input v-model="form.tel" maxlength="500" placeholder="请输入咨询热线"></el-input>
        </el-form-item>
         <el-form-item label="底部邮箱">
          <el-input v-model="form.email" maxlength="200" placeholder="请输入联系邮箱"></el-input>
        </el-form-item>
        <el-form-item label="登录链接">
          <el-input v-model="form.wechat" maxlength="500" placeholder="登录链接"></el-input>
        </el-form-item>
        <el-form-item label="注册链接" >
          <el-input v-model="form.code" maxlength="200" placeholder="注册链接"></el-input>
        </el-form-item>
        
        <el-form-item label="版权信息">
          <script id="copyright" type="text/plain"></script>
        </el-form-item>
     
        <el-form-item>
          <el-button type="primary" @click="submit()">确定</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getWebSite, updateWebSite } from "@/api/settings"
export default {
  name: "websiteInfo",
  data() {
    return {
      form: {
        other1:'',
        other2:'',
        other3:''
      },
      config: {
        autoHeightEnabled: false,
        autoFloatEnabled: false, //是否工具栏可浮动
        autoClearinitialContent: true, //是否自动清除编辑器初始内容，注意：如果focus属性设置为true,这个也为真，那么编辑器一上来就会触发导致初始化的内容看不到了
        initialFrameWidth: null,
        initialFrameHeight: 200,
        UEDITOR_HOME_URL: "static/ueditor/"
      },
      editor: null,
    }
  },
  methods: {
    logoSuccess(response, file, fileList) {
      this.form.logoUrl = response.data.file_name
    },
    logoSuccess1(response, file, fileList) {
      this.form.other1 = response.data.file_name
      console.log(this.form.other1)
    },
    logoSuccess2(response, file, fileList) {
      this.form.other2 = response.data.file_name
    },
    uploadError() {},
    submit() {
      
      if (this.editor != null) {
        this.form.copyright = this.editor.getContent()
      }
      this.form.other3 = ''
      updateWebSite(this.form).then(data => {
        if (data.result) {
          this.$message({
            message: "设置成功！",
            type: "success"
          })
          // this.editor.setContent("")
        } else {
          this.$message.error("设置失败!" + data.errMsg)
        }
      })
    }
  },
  created() {
  },
  mounted() {
    let _this = this
    getWebSite().then(data => {
      this.form = data
      this.editor = UE.getEditor("copyright", this.config) // 初始化UE
      if (data.copyright != null && data.copyright != "") {
          this.editor.addListener("ready", function() {
            _this.editor.setContent(data.copyright) // 确保UE加载完成后，放入内容。
          })
        }
    })
  },
  destroyed() {
    if (this.editor != null) {
      this.editor.destroy()
    }
  }
}
</script>
